package com.example.jbmsuppliers.sinopec.net;

import android.os.Bundle;
import android.os.Handler;

import com.jbm.jbmsupplier.util.BusinessEntity;
import com.jbm.jbmsupplier.util.IAppVersion;
import com.jbm.jbmsupplier.util.ICtrl;
import com.jbm.jbmsupplier.util.IInformationCtrl;
import com.jbm.jbmsupplier.util.abstracts.SendMessageInterfase;
import com.jbm.jbmsupplier.util.enums.InfoType;

/**
 * Created by 家帮忙 on 2017/3/1.
 */

public class NetDeceVersion extends SendMessageInterfase {
    private Handler handler;
    private Bundle mbundle;
    BusinessEntity buobj;
    private final String cmd_key="CMDKEY";
    private final String DECEVERF="DECEVERF";
    private final String REGISBUIN="REGISBUIN";
    private final String ALLACTION="ALLACTION";
    private final String MYISSUE="MYISSUE";
    private final String DELETEMYLLACTION="DELETEMYLLACTION";
    private final String DELETEIUSSE="DELETEIUSSE";
    private final String MERCHANG="MERCHANG";
    private final String COMMOB="COMMOB";
    private final String MODIFYCHANT="MODIFYMERCHANT";
    private final String EXITLOGIN="EXITLOGIN";
    public static final int UPCHANT=000000;


    public NetDeceVersion(Handler handler) {
        this.handler = handler;
    }
    @Override
    protected void RunContext() {
       String cmd= this.mbundle.getString(cmd_key);
if (cmd.equals(DECEVERF)){//检测版本号
    IAppVersion version = gSocket.GetLastVersion("jbm.android", this.mbundle.getInt("max"), this.mbundle.getInt("min"), 0, 0);
    handler.sendMessage(handler.obtainMessage(this.mbundle.getInt("vers"),version));
}else if (cmd.equals(REGISBUIN)){//注册为商家
    ICtrl resultbusin = gSocket.AddBusiness(buobj);
    handler.sendMessage(handler.obtainMessage(this.mbundle.getInt("regisbu"),resultbusin));

} else if (cmd.equals(ALLACTION)){//我的搜藏
       IInformationCtrl resultbusin = gSocket.GetMyFocusInfoList(this.mbundle.getInt("star"),this.mbundle.getInt("end"));
            handler.sendMessage(handler.obtainMessage(this.mbundle.getInt("llact"),resultbusin));

        }else if (cmd.equals(MYISSUE)){//我的发布statics
    IInformationCtrl resultbusin = gSocket.GetMyInfoList(this.mbundle.getInt("statics"), null, this.mbundle.getInt("star"), this.mbundle.getInt("end"));
    handler.sendMessage(handler.obtainMessage(this.mbundle.getInt("llact"),resultbusin));

}else if (cmd.equals(DELETEMYLLACTION)){//取消搜藏
    ICtrl deletellaction = gSocket.FocusCancel(this.mbundle.getInt("infoid"), this.mbundle.getInt("loginid"), this.mbundle.getInt("pyte"));
    handler.sendMessage(handler.obtainMessage(this.mbundle.getInt("llacti"),deletellaction));

}else if (cmd.equals(DELETEIUSSE)){//删除发布
    ICtrl deleteiusse = gSocket.DelInfo(this.mbundle.getInt("orid"));
    handler.sendMessage(handler.obtainMessage(this.mbundle.getInt("iuss"),deleteiusse));

}else if (cmd.equals(MERCHANG)){//检测是不是商家
    BusinessEntity mar = gSocket.GetBusInfo(this.mbundle.getInt("loginid"));

    handler.sendMessage(handler.obtainMessage(this.mbundle.getInt("mar"),mar));

} else if (cmd.equals(COMMOB)){//
    IInformationCtrl goods = gSocket.GetMyInfoList(this.mbundle.getInt("stat"), InfoType.Goods.toValue(), this.mbundle.getInt("star"), this.mbundle.getInt("sed"));
    handler.sendMessage(handler.obtainMessage(this.mbundle.getInt("goods"),goods));


//修改商家接口
}else if(cmd.equals(MODIFYCHANT)){
    //int bus_id,String bus_name,String bus_address,String servicestyle,String sellerscope,String filename,byte[] picbytes,int status


    ICtrl goods = gSocket.ModBusiness(this.mbundle.getInt("bus_id"), this.mbundle.getString("bus_name"), this.mbundle.getString("bus_address"), this.mbundle.getString("servicestyle"), this.mbundle.getString("sellerscope"), this.mbundle.getString("filename"), this.mbundle.getByteArray("picbytes"), this.mbundle.getInt("status"));
    handler.sendMessage(handler.obtainMessage(UPCHANT,goods));


}else  if (cmd.equals(EXITLOGIN)){
    ICtrl exit = gSocket.Logout();
    handler.sendMessage(handler.obtainMessage(this.mbundle.getInt("ext"),exit));


}
    }

    /**
     * 检测版本更新
     */
    public void setDeceVer(int max,int min,int vers){
        this.mbundle=new Bundle();
        this.mbundle.putString(cmd_key,DECEVERF);
        this.mbundle.putInt("max",max);
        this.mbundle.putInt("min",min);
        this.mbundle.putInt("vers",vers);
        this.Run();


    }
/**
 * 注册为商家
 */
public void setRegisBusin(BusinessEntity obj,int regisbu){
    this.mbundle=new Bundle();
    this.mbundle.putString(cmd_key,REGISBUIN);
    this.mbundle.putInt("regisbu",regisbu);
    buobj=obj;
    this.Run();

}

/**
 * 获取我的搜藏
 */

public void setMyllaction(int star,int end,int llact){
    this.mbundle=new Bundle();
    this.mbundle.putString(cmd_key,ALLACTION);
    this.mbundle.putInt("star",star);
    this.mbundle.putInt("end",end);
    this.mbundle.putInt("llact",llact);
    this.Run();
}
    /**
     * 我的发布
     */

    public void setMyIssue(int statics ,int star,int end,int llact){
        this.mbundle=new Bundle();
        this.mbundle.putString(cmd_key,MYISSUE);
        this.mbundle.putInt("statics",statics);
        this.mbundle.putInt("star",star);
        this.mbundle.putInt("end",end);
        this.mbundle.putInt("llact",llact);

        this.Run();
    }
    /**
     * 删除收藏的每一条
     */

    public void setdeleteMyll(int infoid,int loginid,int pyte,int llacti){
        this.mbundle=new Bundle();
        this.mbundle.putString(cmd_key,DELETEMYLLACTION);
        this.mbundle.putInt("infoid",infoid);
        this.mbundle.putInt("loginid",loginid);
        this.mbundle.putInt("pyte",pyte);
        this.mbundle.putInt("llacti",llacti);
        this.Run();
    }
    /**
     * 删除发布的每一条
     */

    public void setdeleteIssue(int orid,int iuss){
        this.mbundle=new Bundle();
        this.mbundle.putString(cmd_key,DELETEIUSSE);
        this.mbundle.putInt("orid",orid);
        this.mbundle.putInt("iuss",iuss);
        this.Run();
    }

    /**
     * 检测是否是商家
     */

public void setMerChant(int loginid,int mar){
    this.mbundle=new Bundle();
    this.mbundle.putString(cmd_key,MERCHANG);
    this.mbundle.putInt("loginid",loginid);
    this.mbundle.putInt("mar",mar);
    this.Run();
}

/**
 * 获取商家的所有商品
 */
public void setGoods(int stat,int star,int sed,int goods){
    this.mbundle=new Bundle();
    this.mbundle.putString(cmd_key,COMMOB);
    this.mbundle.putInt("stat",stat);
    this.mbundle.putInt("star",star);
    this.mbundle.putInt("sed",sed);
    this.mbundle.putInt("goods",goods);
    this.Run();

}

    /**
     * 修改商家
     * int bus_id,String bus_name,String bus_address,String servicestyle,String sellerscope,String filename,byte[] picbytes,int status
     */
    public void setUpdateBusiness(int bus_id,String bus_name,String bus_address,String servicestyle,String sellerscope,String filename,byte[] picbytes,int status){
        this.mbundle=new Bundle();
        this.mbundle.putString(cmd_key,MODIFYCHANT);
        this.mbundle.putInt("bus_id",bus_id);
        this.mbundle.putString("bus_name",bus_name);
        this.mbundle.putString("bus_address",bus_address);
        this.mbundle.putString("servicestyle",servicestyle);
        this.mbundle.putString("sellerscope",sellerscope);
        this.mbundle.putString("filename",filename);
        this.mbundle.putByteArray("picbytes",picbytes);
        this.mbundle.putInt("status",status);
        this.Run();
    }


/**
 * 退出登录
 */
public void setExit(int ext){
    this.mbundle=new Bundle();
    this.mbundle.putString(cmd_key,EXITLOGIN);
    this.mbundle.putInt("ext",ext);
    this.Run();

}





}
